/**
 * 
 */
package com.gragra.sampling.sequentialStructure;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author Christoph Teichmann
 * 01.06.2013
 */
public enum HyphenType implements ExtensionInformationValue
{
	PreHyphen,
	PostHyphen,
	InternalHyphen,
	NoHyphen,
	AllHyphen;
	@Override
	public ExtensionInformationLevel getLevel()
	{return ExtensionLevels.HyphenLevel;}
	/**
	 * 
	 */
	private int number = -1;
	/* (non-Javadoc)
	 * @see com.gragra.sampling.sequentialStructure.ExtensionInformationValue#getNumber()
	 */
	@Override
	public int getNumber()
	{
		if(number < 0)
		{
			for(int i=0;i<HyphenType.values().length;++i)
			{
				if(HyphenType.values()[i] == this)
				{return (number = i);}
			}
		}
		return number;
	}
	/**
	 * 
	 */
	private final static Pattern patt = Pattern.compile("-+");
	/**
	 * 
	 * @param input
	 * @return
	 */
	public static HyphenType classify(String input)
	{
		Matcher mat = patt.matcher(input);
		if(mat.matches())
		{return HyphenType.AllHyphen;}
		mat.reset();
		if(mat.find())
		{
			if(mat.start() == 0)
			{return PreHyphen;}
			else if(mat.end() == input.length())
			{return PostHyphen;}
			else
			{return InternalHyphen;}
		}
		else
		{return NoHyphen;}
	}
}